﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Extract URL address</title>
	<link href="styles/js-console.css" rel="stylesheet" />
	<script src="scripts/string-extensions.js"></script>
</head>
<body>							  

	<label for="url">Enter a url adress in format "http://www.abv.bg/login/password"! </label>
	<input id="url" type="text" class="js-console-input" />
	<a href="#" class="js-console-btn" onclick="parseURL()">Parse the URL to JSON object and print it!</a>
	<div id="js-console"></div>
	<script src="scripts/js-console.js"></script>
	<script>

	    function parseURL() {
	        var url = jsConsole.read("#url");
	        jsConsole.writeLine(url);
	        var protokol = url.substring(0, url.indexOf(":"));
	        var server = url.substring(url.indexOf(":") + 3, url.indexOf("/", url.indexOf(":") + 3));
	        var resource = url.substr(url.indexOf("/", url.indexOf(":") + 3) + 1)
	        var URLJSON = { "Protocol": protokol, "Server": server, "Resource": resource };
	        jsConsole.writeLine("Protocol :" + URLJSON.Protokol);
	        jsConsole.writeLine("Server :" + URLJSON.Server);
	        jsConsole.writeLine("Resource :" + URLJSON.Resource);
	    }


	</script>

</body>
</html>